package com.bdth.weget.business.component;

import com.bdth.weget.business.entity.Cars;
import com.bdth.weget.business.entity.Location;
import com.bdth.weget.business.service.*;
import com.bdth.weget.vo.JT0200;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Administrator on 2019/7/15.
 */
@Component
@RabbitListener(queues = RabbitmqQueue.LOCATION_QUEUE)
public class RabbitmqReceive {

    @Autowired
    private LocationService locationService;

    @Autowired
    private LocationHisService locationHisService;

    @Autowired
    private WarnningService warnningService;

    @Autowired
    private StatusService statusService;

    @Autowired
    private CarsService carsService;

    @RabbitHandler
    public void process(JT0200 bean) {
        System.out.println("receive\r\n"+bean.toString());
        //保存位置信息
        Location location = locationService.findBySimno(bean.getSimno());
        Cars cars = carsService.findCarsBySimno(bean.getSimno());
        bean.setCarid(cars.getId());
        locationService.saveLocation(bean);
        locationHisService.insert(bean);
        //保存告警信息
        List<String> warnList = bean.getAlarmFlag().toList();
        if(warnList!=null&&warnList.size()>0){
            warnningService.insert(bean);
        }
        //保存状态信息
        statusService.saveStatus(bean);
    }
}
